<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app">
        fdafda{{message}}fdafdsa
        <div>
            fdafdsa{{mydata}}fdsafd
            <div>
                <div>
                    <div></div>
                </div>
            </div>
        </div>
    </div>
    <script>
        var data = {
            message:"你好",
            mydata:"张三"
        }


        var appEle  =document.querySelector("#app");
        // console.log(appEle.innerHTML);
        // var str = appEle.innerHTML;
        // var reg = /{{(\w+)}}/g;
        
        // if(reg.test(str)){
        //     var key = RegExp.$1;
        //     console.log(key);
        //      str =  str.replace(reg,data[key]);
        //   console.log(str);
        // }

        // str.replace(reg,)

        var childnodes = appEle.childNodes;
        // console.log(childnodes);
        childnodes.forEach(function(node){
            if(node.nodeType==3){
                var content = node.textContent;
                // console.log(content);
                var reg = /{{(\w+)}}/g;
                if(reg.test(content)){
                    var key = RegExp.$1;
                    node.textContent = node.textContent.replace(reg,data[key]);
                }
            }

        })





    </script>
</body>
</html>